//
//  HamatonHomeCollectionView.swift
//  hamaton-app
//
//  Created by intyt on 2024/3/26.
//

import UIKit
import SnapKit

class HamatonHomeCollectionHeader: UICollectionReusableView {
    
    lazy var topImageView: UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "home_1"))
        addSubview(imageView)
        return imageView
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .red
        topImageView.snp.makeConstraints {
            $0.top.bottom.left.right.equalToSuperview()
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class HamatonHomeCollectionCell: UICollectionViewCell {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        topImageView.snp.makeConstraints {
            $0.top.equalToSuperview().offset(12)
            $0.centerX.equalToSuperview()
            $0.width.height.equalTo(80)
        }

        titleLabel.snp.makeConstraints {
            $0.centerX.equalToSuperview()
            $0.top.equalTo(topImageView.snp.bottom).offset(12)
        }
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var topImageView: UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "home_1"))
        contentView.addSubview(imageView)
        return imageView
    }()
    
    lazy var titleLabel: UILabel = {
        let label = UILabel(frame: .zero)
        label.font = Theme.Font.size(14)
        label.textColor = UIColor(hex6: 0x404040)
        label.numberOfLines = 1
        label.textAlignment = .center
        label.text = "标题"
        contentView.addSubview(label)
        return label
    }()
    
    func updateHomeModel(model: HamatonHomeModel)  {
        topImageView.image = UIImage(named: model.picName)
        titleLabel.text = model.name
    }
}

